<template>
    <div>
        <el-dialog v-model="showView" title="对单管家" width="990" :before-close="handleClose">
            <!-- <div>
                <el-button type="primary" class="mb-4 ml-4" @click="add_butler">添加对单管家</el-button>
            </div> -->
            <div>
                <el-table size="mini" :data="lists">
                    <el-table-column label="序号" type="index" min-width="80" />
                    <el-table-column label="账号" min-width="120" prop="account"/>
                    <el-table-column label="名字" min-width="120" prop="real_name"/>
                    <el-table-column label="头像" min-width="100" prop="avatar">
                         <template #default="{ row }">
                            <div class="flex align-middle">
                                <el-image style="width: 38px; height: 38px"
                                        :src="row.avatar"
                                        :zoom-rate="1.2"
                                        :max-scale="7"
                                        :min-scale="0.2" 
                                        fit="contain"
                                        :preview-teleported="true"
                                        :preview-src-list="[row.avatar]"></el-image>
                            </div>
                        </template>
                    </el-table-column>
                    <!-- <el-table-column label="对单中群聊" min-width="100" prop="status1_count"/>
                    <el-table-column label="合作中群聊" min-width="100" prop="status2_count"/>
                    <el-table-column label="无状态群聊" min-width="100" prop="status3_count"/>
                    <el-table-column label="群聊解散" min-width="100" prop="status4_count"/> -->
                    <el-table-column label="操作" min-width="100">
                        <template #default="{ row }">
                            <el-button size="small" type="primary" @click="onChoose(row)">选择</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
        </el-dialog>

        <!-- <person_demand ref="checkDemand" :is_person="true" @backAdmin="backAdmin"></person_demand> -->
    </div>
</template>
<script lang="ts" setup>
import { butlerList, saveButler } from '@/api/group';
// import person_demand from './person_demand.vue'
const showView = ref(false)
const lists:any = ref([])
const init = () => {
    getList()
    showView.value = true;
}
const getList = async () => {
    const res = await butlerList({})
    console.log(res)
    res.map((item:any) => {
        item.is_default_copy = item.is_default; // 标记数据已初始化
    });
    lists.value = res;
}
const emit = defineEmits(['backClose', 'backGj'])
const handleClose = () => {
    emit('backClose', '')
    showView.value = false;
}
// ---添加管家
const checkDemand = ref()
// const add_butler = () => {
//     checkDemand.value.add();
// }
const onChoose = (row:any) => {
    emit('backGj', row)
    showView.value = false;
}
// 选择管理员返回
// const backAdmin = async (row: any)=> {
//     console.log('backAdmin')
//     console.log(row)
//     await saveButler({
//         user_id: row.id,
//         is_default: 1
//     })
//     getList()
// }
// const changeStatus = async (val: any, row: any) => {
//     console.log(val)
//     console.log('copy'+row.is_default_copy)
//     if (val != row.is_default_copy) {
//          await saveButler({
//             user_id: row.user_id,
//             is_default: val
//         })
//         getList()
//     }   
// }

defineExpose({
    init
})
</script>